{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "患病样本基因组数据文件总数: 7\n",
      "正常样本基因组数据文件总数: 11\n",
      "总样本基因组数据文件数: 18\n",
      "患病样本文件名 ['Base-data/AD\\\\006_S_4153.csv', 'Base-data/AD\\\\006_S_4192.csv', 'Base-data/AD\\\\018_S_4733.csv', 'Base-data/AD\\\\019_S_4252.csv', 'Base-data/AD\\\\019_S_4477.csv', 'Base-data/AD\\\\019_S_5012.csv', 'Base-data/AD\\\\019_S_5019.csv']\n",
      "正常样本文件名 ['Base-data/HC\\\\002_S_4213.csv', 'Base-data/HC\\\\002_S_4225.csv', 'Base-data/HC\\\\002_S_4262.csv', 'Base-data/HC\\\\002_S_4264.csv', 'Base-data/HC\\\\002_S_4270.csv', 'Base-data/HC\\\\006_S_4150.csv', 'Base-data/HC\\\\006_S_4357.csv', 'Base-data/HC\\\\006_S_4449.csv', 'Base-data/HC\\\\006_S_4485.csv', 'Base-data/HC\\\\012_S_4026.csv', 'Base-data/HC\\\\013_S_4579.csv']\n",
      "总样本文件名 ['006_S_4153', '006_S_4192', '018_S_4733', '019_S_4252', '019_S_4477', '019_S_5012', '019_S_5019', '002_S_4213', '002_S_4225', '002_S_4262', '002_S_4264', '002_S_4270', '006_S_4150', '006_S_4357', '006_S_4449', '006_S_4485', '012_S_4026', '013_S_4579']\n"
     ]
    }
   ],
   "source": [
    "import glob, os\n",
    "from os import getcwd\n",
    "from os import listdir\n",
    "import pandas as pd \n",
    "import numpy as np\n",
    "ad_files_num=len(os.listdir('Base-data/AD'))\n",
    "hc_files_num=len(os.listdir('Base-data/HC'))\n",
    "print(\"患病样本基因组数据文件总数:\",ad_files_num)\n",
    "print(\"正常样本基因组数据文件总数:\",hc_files_num)\n",
    "files_num=ad_files_num+hc_files_num\n",
    "print(\"总样本基因组数据文件数:\",files_num) \n",
    "adfiles = glob.glob(os.path.join('Base-data/AD/*.csv'))\n",
    "hcfiles = glob.glob(os.path.join('Base-data/HC/*.csv'))\n",
    "print (\"患病样本文件名\",adfiles)\n",
    "print (\"正常样本文件名\",hcfiles)\n",
    "allfiles = adfiles+hcfiles\n",
    "allfiles_name=[]\n",
    "for filepath in allfiles:\n",
    "    allfiles_name.append(filepath.split('.')[0].split('\\\\')[1])\n",
    "print (\"总样本文件名\",allfiles_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SNP Name</th>\n",
       "      <th>Allele1 - Forward</th>\n",
       "      <th>Allele2 - Forward</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>rs1000000</td>\n",
       "      <td>T</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>rs1000002</td>\n",
       "      <td>A</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>rs10000023</td>\n",
       "      <td>T</td>\n",
       "      <td>T</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>rs1000003</td>\n",
       "      <td>A</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>rs10000030</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     SNP Name Allele1 - Forward Allele2 - Forward\n",
       "0   rs1000000                 T                 C\n",
       "1   rs1000002                 A                 G\n",
       "2  rs10000023                 T                 T\n",
       "3   rs1000003                 A                 G\n",
       "4  rs10000030                 G                 G"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_normal =  pd.read_csv(\"Base-data/AD/006_S_4153.csv\",header=0,index_col=False,usecols=[4,7,8])#从0行开始算，重新设置一列成为index值\n",
    "df_normal.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SNP Name</th>\n",
       "      <th>Allele1 - Forward</th>\n",
       "      <th>Allele2 - Forward</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>rs1000000</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>rs1000002</td>\n",
       "      <td>A</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>rs10000023</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>rs1000003</td>\n",
       "      <td>A</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>rs10000030</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     SNP Name Allele1 - Forward Allele2 - Forward\n",
       "0   rs1000000                 C                 C\n",
       "1   rs1000002                 A                 G\n",
       "2  rs10000023                 G                 G\n",
       "3   rs1000003                 A                 A\n",
       "4  rs10000030                 G                 G"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_wrong =  pd.read_csv(\"Base-data/AD/018_S_4733.csv\",header=0,index_col=False,usecols=[4,7,8])#从0行开始算，重新设置一列成为index值\n",
    "df_wrong.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SNP Name</th>\n",
       "      <th>Allele1 - Forward_x</th>\n",
       "      <th>Allele2 - Forward_x</th>\n",
       "      <th>Allele1 - Forward_y</th>\n",
       "      <th>Allele2 - Forward_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>rs1000000</td>\n",
       "      <td>T</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>rs1000002</td>\n",
       "      <td>A</td>\n",
       "      <td>G</td>\n",
       "      <td>A</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>rs10000023</td>\n",
       "      <td>T</td>\n",
       "      <td>T</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>rs1000003</td>\n",
       "      <td>A</td>\n",
       "      <td>G</td>\n",
       "      <td>A</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>rs10000030</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>730520</th>\n",
       "      <td>VGXS34742</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>730521</th>\n",
       "      <td>VGXS34743</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>730522</th>\n",
       "      <td>VGXS34744</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>730523</th>\n",
       "      <td>VGXS34761</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>730524</th>\n",
       "      <td>VGXS35706</td>\n",
       "      <td>T</td>\n",
       "      <td>T</td>\n",
       "      <td>T</td>\n",
       "      <td>T</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>730525 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          SNP Name Allele1 - Forward_x Allele2 - Forward_x  \\\n",
       "0        rs1000000                   T                   C   \n",
       "1        rs1000002                   A                   G   \n",
       "2       rs10000023                   T                   T   \n",
       "3        rs1000003                   A                   G   \n",
       "4       rs10000030                   G                   G   \n",
       "...            ...                 ...                 ...   \n",
       "730520   VGXS34742                   C                   C   \n",
       "730521   VGXS34743                   G                   G   \n",
       "730522   VGXS34744                   G                   G   \n",
       "730523   VGXS34761                   C                   C   \n",
       "730524   VGXS35706                   T                   T   \n",
       "\n",
       "       Allele1 - Forward_y Allele2 - Forward_y  \n",
       "0                        C                   C  \n",
       "1                        A                   G  \n",
       "2                        G                   G  \n",
       "3                        A                   A  \n",
       "4                        G                   G  \n",
       "...                    ...                 ...  \n",
       "730520                   C                   C  \n",
       "730521                   G                   G  \n",
       "730522                   G                   G  \n",
       "730523                   C                   C  \n",
       "730524                   T                   T  \n",
       "\n",
       "[730525 rows x 5 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_new=pd.merge(df_normal, df_wrong, on='SNP Name',how='left')\n",
    "df_new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SNP Name</th>\n",
       "      <th>Allele1 - Forward</th>\n",
       "      <th>Allele2 - Forward</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>rs1000000</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>rs1000002</td>\n",
       "      <td>A</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>rs10000023</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>rs1000003</td>\n",
       "      <td>A</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>rs10000030</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>730520</th>\n",
       "      <td>VGXS34742</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>730521</th>\n",
       "      <td>VGXS34743</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>730522</th>\n",
       "      <td>VGXS34744</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>730523</th>\n",
       "      <td>VGXS34761</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>730524</th>\n",
       "      <td>VGXS35706</td>\n",
       "      <td>T</td>\n",
       "      <td>T</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>730525 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          SNP Name Allele1 - Forward Allele2 - Forward\n",
       "0        rs1000000                 C                 C\n",
       "1        rs1000002                 A                 G\n",
       "2       rs10000023                 G                 G\n",
       "3        rs1000003                 A                 A\n",
       "4       rs10000030                 G                 G\n",
       "...            ...               ...               ...\n",
       "730520   VGXS34742                 C                 C\n",
       "730521   VGXS34743                 G                 G\n",
       "730522   VGXS34744                 G                 G\n",
       "730523   VGXS34761                 C                 C\n",
       "730524   VGXS35706                 T                 T\n",
       "\n",
       "[730525 rows x 3 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_new1 = pd.DataFrame()\n",
    "df_new1['SNP Name']=df_new['SNP Name']\n",
    "df_new1['Allele1 - Forward']=df_new['Allele1 - Forward_y']\n",
    "df_new1['Allele2 - Forward']=df_new['Allele2 - Forward_y']\n",
    "df_new1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n",
      "修复成功\n"
     ]
    }
   ],
   "source": [
    "for filepath in allfiles:\n",
    "    df_normal =  pd.read_csv(\"Base-data/AD/006_S_4153.csv\",header=0,index_col=False,usecols=[4,7,8])#从0行开始算，重新设置一列成为index值\n",
    "    df_wrong =  pd.read_csv(filepath,header=0,index_col=False,usecols=[4,7,8])#从0行开始算，重新设置一列成为index值\n",
    "    df_new=pd.merge(df_normal, df_wrong, on='SNP Name',how='left')\n",
    "    df_fix = pd.DataFrame()\n",
    "    df_fix['SNP Name']=df_new['SNP Name']\n",
    "    df_fix['Allele1 - Forward']=df_new['Allele1 - Forward_y']\n",
    "    df_fix['Allele2 - Forward']=df_new['Allele2 - Forward_y']\n",
    "    fix_filepath=filepath.replace(\"Base-data\", \"fix-data\")\n",
    "    df_fix.fillna('-',inplace=True)\n",
    "    df_fix.to_csv(fix_filepath, index = False, sep=',', encoding='utf-8')#保存修复之后的文件\n",
    "    print(\"修复成功\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "left = pd.DataFrame({'snp_name': ['K0', 'K1', 'K2', 'K3'],\n",
    "                      'A': ['A0', 'A1', 'A2', 'A3'],\n",
    "                      'B': ['B0', 'B1', 'B2', 'B3']})\n",
    "\n",
    "right = pd.DataFrame({'snp_name': ['K0', 'K1', 'K4', 'K5'],\n",
    "                      'A': ['C0', 'C1', 'C4', 'C5'],\n",
    "                      'B': ['D0', 'D1', 'D4', 'D5']})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>snp_name</th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>K0</td>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>K1</td>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>K2</td>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>K3</td>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  snp_name   A   B\n",
       "0       K0  A0  B0\n",
       "1       K1  A1  B1\n",
       "2       K2  A2  B2\n",
       "3       K3  A3  B3"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "left"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>snp_name</th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>K0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>K1</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>K4</td>\n",
       "      <td>C4</td>\n",
       "      <td>D4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>K5</td>\n",
       "      <td>C5</td>\n",
       "      <td>D5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  snp_name   A   B\n",
       "0       K0  C0  D0\n",
       "1       K1  C1  D1\n",
       "2       K4  C4  D4\n",
       "3       K5  C5  D5"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "right"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>snp_name</th>\n",
       "      <th>A_x</th>\n",
       "      <th>B_x</th>\n",
       "      <th>A_y</th>\n",
       "      <th>B_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>K0</td>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>K1</td>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>K2</td>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>K3</td>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  snp_name A_x B_x A_y B_y\n",
       "0       K0  A0  B0  A0  B0\n",
       "1       K1  A1  B1  A1  B1\n",
       "2       K2  A2  B2  A2  B2\n",
       "3       K3  A3  B3  A3  B3"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(left, left, on='snp_name',how='left')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
